package com.zmn.oms.api.listener;

import com.alibaba.fastjson.JSON;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.manager.utils.OmsMqTagConsts;
import com.zmn.oms.model.dto.order.OrderOperationInstructionMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 类描述：监听订单操作指令，根据指令对订单做相应的操作
 *
 * @author lhl
 * @date 2020/01/10 18:20
 */
@Slf4j
@AliyunMQListener(topic = "${spring.mq.topic.oms}")
@Component
public class OrderOperationInstructionListener {

    /**
     * 收到订单操作指令
     *
     * @param message
     */
    @AliyunMQHandler(tags = OmsMqTagConsts.ZMN_TOPIC_OMS_ORDER_OPERATION_INSTRUCTION_API)
    public void onMessage(String message) {
        try {
            log.info("#mq#order#operationInstruction#recive message:{}", message);
            OrderOperationInstructionMessage orderOperationInstructionMessage
                    = JSON.parseObject(message, OrderOperationInstructionMessage.class);

            Integer operation = orderOperationInstructionMessage.getOperation();

            // 取消订单
            if (Objects.equals(OrderConsts.ORDER_OP_TYPE_CANCEL, operation)) {
                //CancelOrderFacade cancelOrderFacade = SpringBeanFactoryUtil.getBean("cancelOrderFacade");
                //cancelOrderFacade.cancelOrderByOperationInstructionMessage(orderOperationInstructionMessage);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
